﻿using ModelDesignEduse.Framework;
using ModelDesignEduse.TableProjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WorkbenchTest
{
    public class PageTypeCategorySelector : Selector
    {
        public PageTypeCategorySelector()
        {
            this.ColumnHeader = "Sayfa Kategorisi";
            this.Readonly = true;
        }

        public override object Select(object cell_value)
        {
            var selectorForm = new SelectorForm("Sayfa Şablonu", "Sayfa Şablonu Seçimi");

            selectorForm.FillDatabase += selectorForm_FillDatabase;

            switch (selectorForm.ShowDialog())
            {
                case DialogResult.OK:
                    break;
                case DialogResult.Cancel:
                    break;
            }

            return (selectorForm.SelectedItem as PageTypeCategory).page_type_category_id.ToString();
        }

        List<object> selectorForm_FillDatabase()
        {
            var pageTypeCategories = new List<object>();
            var reader = CRUD.ExecuteCommandList("call get_all_page_type_categories();");

            while (reader.Read())
            {
                PageTypeCategory ptc = new PageTypeCategory();
                ptc.page_type_category_id = reader.GetInt32("page_type_category_id");
                ptc.page_type_category_name = reader["page_type_category_name"] as string;
                pageTypeCategories.Add(ptc);
            }

            reader.Close();

            return pageTypeCategories;
        }
    }
}
